//
//  LCNewsHTMLViewController+WKWebView.m
//  JK九酷云头条
//
//  Created by admin on 2018/3/7.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LCNewsHTMLViewController+WKWebView.h"

@implementation LCNewsHTMLViewController (WKWebView)

#pragma mark - naviBar
- (void)naviBarOne{
    self.navigationController.navigationItem.hidesBackButton = YES;//隐藏系统的返回按钮
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50,34)];
    [backButton setTitle:@"返回" forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:@"home_nav_button_back"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [backButton setTitleColor:RGBColor(89, 196, 120) forState:UIControlStateNormal];
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItems = @[backBarButtonItem];
}

- (void)naviBarMore{
    self.navigationController.navigationItem.hidesBackButton = YES;//隐藏系统的返回按钮
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50,34)];
    [backButton setTitle:@"返回" forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:@"home_nav_button_back"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [backButton setTitleColor:RGBColor(89, 196, 120) forState:UIControlStateNormal];
    
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    UIBarButtonItem *closeBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStyleDone target:self action:@selector(close)];
    [closeBarButtonItem setTintColor:RGBColor(89, 196, 120)];
    self.navigationItem.leftBarButtonItems = @[backBarButtonItem,closeBarButtonItem];
}
- (void)close {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)back {
    [SVProgressHUD dismiss];
    if (self.webView.canGoBack) {
        [self.webView goBack];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}
- (void)setupTitleImageView {
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.bounds = CGRectMake(0, 0, 70, 20);
    imageView.image = [UIImage imageNamed:@"title"];
    self.navigationItem.titleView = imageView;
}

#pragma mark - createWebView
- (WKWebView *)createWebView:(WKWebView *)webView playUrlStr:(NSString *)playUrlStr {
    webView = [[WKWebView alloc] init];
    webView.allowsBackForwardNavigationGestures = YES;//是否允许左右划手势导航,默认不允许
    NSURL *url = [NSURL URLWithString:playUrlStr];
    NSURLRequest *request =[NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
    return webView;
}

@end
